#!/bin/bash

help() {
  echo "Usage:"
  echo "  zmicro plugin list"
  echo ""
}

core() {
  if [ "$0" = "-h" ] || [ "$0" = "--help" ]; then
    help
    exit 0
  fi

  local plugins=$(plugin::list_names)
  local plugin_count=$(array::length $plugins)

  if [ $plugin_count -eq 0 ]; then
    log "    (no avaliable plugins)"
    exit 0
  fi

  log "zmicro plugins: $plugin_count"
  log ""

  print() {
    local index=$1
    local plugin_name=${@:2}

    log "    $index $(color::success "$plugin_name")($(plugin::get_version $plugin_name)) - $(plugin::get_description $plugin_name)"
  }

  array::each print $plugins
}

run() {
  core $@
}

run $@
